/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAOS.DAOSADMINISTRACION;

import Entidades.EntidadesAdministracion.Rolespersona;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author daniel
 */
@Stateless
@LocalBean
public class RolespersonaDAOS {

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
   @PersistenceContext
    EntityManager em;
    public void crear(Rolespersona rp) {
        em.persist(rp);
    }

    public void actualizar(Rolespersona rp) {
        em.merge(rp);
    }

    public void borrar(Integer id) {
        Rolespersona rp = em.find(Rolespersona.class, id);
        em.remove(rp);
    }

    public void guardar(Rolespersona rp) {
        if (rp.getIdRolesPersona() == null) {
            crear(rp);
        } else {
            actualizar(rp);
        }
    }

    public List<Rolespersona> BuscarTodosRolesPersona() {
        return em.createNamedQuery("Rolespersona.findAll", Rolespersona.class).getResultList();
    }

    public List<Rolespersona> BuscarRolesPersona(String cadena) {
        return em.createNamedQuery("Rolespersona.findByIdRolesPersona", Rolespersona.class)
                .setParameter("roles persona", cadena).getResultList();
    }
  
}
